<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>63_使用工厂方法创建对象.html</title>
    <script type="text/javascript">
        /**
         * 使用工厂方法创建对象
         *  通过此方法可以大批量的创建对象
         * 
        */
        function createPerson(name,age,gender){
            //创建一个新的对象
            var obj = new Object();

            //向对象中添加属性
            obj.name = name;
            obj.age = age;
            obj.gender = gender;
            obj.sayName = function(){
                alert(this.name);
            };

            //返回对象
            return obj;
        }

        var obj1 = createPerson("孙悟空",18,"男");
        var obj2 = createPerson("猪八戒",28,"男");
        console.log(obj1);
        console.log(obj2);

    </script>
</head>
<body>
    
</body>
</html>